package com.atgm.mall.gmmailmember.controller;

import com.atgm.common.utils.R;
import com.atgm.mall.gmmailmember.service.MemberThumbsArticleService;
import com.atgm.mall.gmmailmember.vo.resp.ArticleThumbsRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("gmmallmember/memberarticlethumbs")
public class MemberThumbsArticleController {

    @Autowired
    private MemberThumbsArticleService memberArticleThumbsService;

    /**
     * 点赞/取消点赞
     * @param memberId
     * @param articleId
     * @return
     */
    @GetMapping("/saveThumbs/{memberId}/{articleId}")
    public R saveThumbs(@PathVariable("memberId") Long memberId, @PathVariable("articleId") Long articleId) {
        memberArticleThumbsService.saveThumbsInfo(memberId, articleId);
        return R.ok();
    }

    /**
     * 根据文章id获取改文章的点赞数量、会员
     * @param articleId
     * @return
     */
    @GetMapping("/getThumbs/{articleId}")
    public R getThumbsByArticleId(@PathVariable("articleId") Long articleId) {
        ArticleThumbsRespVo articleThumbsRespVo = memberArticleThumbsService.queryArticleThumbsByArticleId(articleId);
        return R.ok().setData(articleThumbsRespVo);
    }

    @GetMapping("/isThumbsArticle/{articleId}/{memberId}")
    public R isThumbsArticle(@PathVariable("articleId") Long articleId, @PathVariable("memberId") Long memberId) {
        Integer flag = memberArticleThumbsService.haveThumbsArticle(articleId, memberId);
        return R.ok().setData(flag);
    }

}
